package com.framework.service.core;

import org.junit.runners.model.InitializationError;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * @author zhoubb
 * @version V1.0
 * @Date 2020/1/26 13:17
 * @since JDK 1.8
 */
public class DefaultSpringJUnitRunner extends SpringJUnit4ClassRunner {

    public DefaultSpringJUnitRunner(Class<?> clazz) throws InitializationError {
        super(clazz);
        System.setProperty("spring.boot.testMainclass", findSuperClass(clazz).getName());
    }


    public static Class<?> findSuperClass(Class<?> clazz){
        Class<?> superCls = clazz.getSuperclass();
        if(superCls == Object.class){
            return clazz;
        }
        return findSuperClass(superCls);
    }
}
